package com.tourism.controller;

import com.github.pagehelper.PageInfo;
import com.tourism.entity.HotelOrder;
import com.tourism.entity.HotelOrderQuery;
import com.tourism.entity.OrderPayInfo;
import com.tourism.exception.GlobalException;
import com.tourism.service.HotelOrderService;
import com.tourism.util.common.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @Description 酒店订单相关的控制器
 * @Author z
 * @Date 2021-03-01 20:40
 */
@Controller
@RequestMapping("/hotelOrder")
public class HotelOrderController {


    @Autowired
    private HotelOrderService hotelOrderService;

    /**
     * 根据酒店订单id查询酒店订单信息
     *
     * @param id
     * @return
     */
    @GetMapping("/getHotelOrderById")
    @ResponseBody
    public HotelOrder getHotelOrderById(Long id) {
        return hotelOrderService.getHotelOrderById(id);
    }

    /**
     * 根据酒店订单id取消酒店订单信息
     *
     * @param id
     * @return
     */
    @GetMapping("/deleteHotelOrder")
    @ResponseBody
    public boolean deleteHotelOrder(Long id) throws GlobalException {
        return hotelOrderService.deleteHotelOrder(id);
    }


    /**
     * 新增酒店订单
     *
     * @param hotel
     * @return
     */
    @PostMapping("/addHotelOrder")
    @ResponseBody
    public Response addHotel(@RequestBody HotelOrder hotel) throws GlobalException {

        return Response.success(hotelOrderService.addHotelOrder(hotel));

    }

    /**
     * 支付酒店订单
     *
     * @param orderPayInfo
     * @return
     */
    @PostMapping("/updateOrderPayInfo")
    @ResponseBody
    public Response updateOrderPayInfo(@RequestBody OrderPayInfo orderPayInfo) {

        return Response.success(hotelOrderService.updateOrderPayInfo(orderPayInfo));

    }


    /**
     * 查询酒店订单列表
     *
     * @param hotelOrderQuery
     * @return
     */
    @PostMapping("/getHotelOrderList")
    @ResponseBody
    public PageInfo<HotelOrder> getHotelOrderList(@RequestBody HotelOrderQuery hotelOrderQuery) {
        return hotelOrderService.getHotelOrderList(hotelOrderQuery);
    }

}
